<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\admin\model\Music as MusicModel;

use app\common\model\Category as CategoryModel;
use fast\Tree;


/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
	protected $model = null;
	protected $categorylist = [];

    /**
     * 首页
     *
     */
    public function index()
    {
		/*音乐接口*/
		$MusicList = MusicModel::where('')->order('id desc')->select();
		//dump($list);
		if(!$MusicList){ $this->error('暂无数据');}
		
		/*分类接口*/
		$this->model = model('app\common\model\Category');  //或者使用助手函数`model`
		$tree = Tree::instance();
		//dump($tree);
		$tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
		//dump($tree);
		$this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
		//dump($this->categorylist);
		$categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
		//dump($categorydata);
		foreach ($this->categorylist as $k => $v) {
			
		    $categorydata[$v['id']] = $v;
		}
		//dump($categorydata);
		$typeList = CategoryModel::getTypeList();
		//dump($typeList);
			
				
		
			
        $this->success('请求成功',["MusicList"=>$MusicList,"typeList"=>$typeList,"parentList"=>$categorydata]);
    }
}
